<?php


Zend_Loader::loadClass("Application_Plotter_Base");
Zend_Loader::loadClass("Application_Table");
Zend_Loader::loadClass('Output_Time');
Zend_Loader::loadClass('Output_ReportVariableData');
Zend_Loader::loadClass('Output_ReportVariableDataDictionary');
Zend_Loader::loadClass('Application_HTMLAccess');
Zend_Loader::loadClass('Application_ReportData');

class ZoneHeatingSummary extends Application_Plotter_Base
{
	private $_tables;
	
	
	
	public function call() {
		/*
		$stmt = $this->_db->query('
			SELECT Month, Day, Hour, Minute, VariableValue
			FROM ReportVariableData
			INNER JOIN ReportVariableDataDictionary ON ReportVariableData.ReportVariableDataDictionaryIndex=ReportVariableDataDictionary.ReportVariableDataDictionaryIndex
			INNER JOIN Time ON ReportVariableData.TimeIndex = Time.TimeIndex
			WHERE ReportVariableDataDictionary.VariableName = ?
		', array ("Zone/Sys Sensible Heating Energy"));
		$results = $stmt->fetchAll($query);
		if (!empty($results)) {
			foreach ($results as &$result) {
				$dataPoints[] = (float) $result['VariableValue']*0.000001;
				$somma=$somma+$result['VariableValue']*0.000001;
			}
			$table = new Application_Table();
			$table->addBaseColumn();
			$table->addColumn("ZONE/SYS SENSIBLE HEATING ENERGY", "MJ",$dataPoints, $somma, 0, 0);
		}	
		
		$stmt = $this->_db->query('
					SELECT Month, Day, Hour, Minute, VariableValue
					FROM ReportVariableData
					INNER JOIN ReportVariableDataDictionary ON ReportVariableData.ReportVariableDataDictionaryIndex=ReportVariableDataDictionary.ReportVariableDataDictionaryIndex
					INNER JOIN Time ON ReportVariableData.TimeIndex = Time.TimeIndex
					WHERE ReportVariableDataDictionary.VariableName = ?
				', array ("Zone/Sys Sensible Heating Rate"));
		$resultsRate = $stmt->fetchAll($query);
		if (!empty($resultsRate)) {
			foreach ($resultsRate as &$resultRate) {
				$dataPointsRate[] = (float) $resultRate['VariableValue'];
				$dataPointsData[] = $resultRate['Day']."-".$resultRate['Month']."-".$resultRate['Hour'].":".$resultRate['Minute'];
				$sommaRate=$sommaRate+$resultRate['VariableValue'];
			}
			$table->addColumn("ZONE/SYS SENSIBLE HEATING RATE", "W" ,$dataPointsRate, $sommaRate, 0, 0);
			$table->addColumn("ZONE/SYS SENSIBLE HEATING RATE {TIMESTAMP}", " " , $dataPointsData, 0 , 0, 0);
		}
		/*
		    $report = array();
		    if (($handle = fopen(APPLICATION_PATH . "/resources/fileOutput.tab", "r")) !== FALSE) {
		    	while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
		            //Zend_Debug::dump($data);
		            $report[$i]=$data;
		            $i++;
		    }
		    Zend_Debug::dump($report);
			return $table;
				
	}*/
		/*
		$html = new DOMDocument();
		@$html->loadHtmlFile(APPLICATION_PATH . '/resources/fileOutput.html');
		$xpath = new DOMXPath( $html );
		$nodelist = $xpath->query( "//body/table[1]/tr/td" );
		*/
		
		//accedo al file HTML attraverso la classe HTML Access
	    $html=new Application_HTMLAccess();
	    $report = new Application_ReportData();
	    //eseguo la query alle tabelle componenti il report
	    $report->addTable("", $html->getQueryResults(13), 5);
	    //$report->addTable("Window-Wall Ratio", $html->getQueryResults(2), 6);
	    //$report->addTable("Skylight-Roof Ratio", $html->getQueryResults(3), 2);
	    //$report->addTable("Zone Summary", $html->getQueryResults(4), 10);
	    //Zend_Debug::dump($nodelist->length); exit;
		//accedo al singolo campo della tabella
		//Zend_Debug::dump($this->_tables[0]->item(3)->nodeValue);
		/*foreach ($nodelist as $n){
			echo $n->nodeValue."\n";
		}*/
		
	
		
		return $report;
}
}
